package com.ruoyi.buss.report.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.buss.utils.DateUtilss;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.buss.report.mapper.ReportDkjgZrrdhLsbMapper;
import com.ruoyi.buss.report.domain.ReportDkjgZrrdhLsb;
import com.ruoyi.buss.report.service.IReportDkjgZrrdhLsbService;

/**
 * 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6Service业务层处理
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Service
public class ReportDkjgZrrdhLsbServiceImpl implements IReportDkjgZrrdhLsbService 
{
    @Autowired
    private ReportDkjgZrrdhLsbMapper reportDkjgZrrdhLsbMapper;

    /**
     * 查询贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     * 
     * @param sjrq 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6ID
     * @return 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     */
    @Override
    public ReportDkjgZrrdhLsb selectReportDkjgZrrdhLsbById(String sjrq)
    {
        return reportDkjgZrrdhLsbMapper.selectReportDkjgZrrdhLsbById(sjrq);
    }

    /**
     * 查询贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6列表
     * 
     * @param reportDkjgZrrdhLsb 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     * @return 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     */
    @Override
    public List<ReportDkjgZrrdhLsb> selectReportDkjgZrrdhLsbList(ReportDkjgZrrdhLsb reportDkjgZrrdhLsb)
    {
        return reportDkjgZrrdhLsbMapper.selectReportDkjgZrrdhLsbList(reportDkjgZrrdhLsb);
    }

    /**
     * 新增贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     * 
     * @param reportDkjgZrrdhLsb 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     * @return 结果
     */
    @Override
    public int insertReportDkjgZrrdhLsb(ReportDkjgZrrdhLsb reportDkjgZrrdhLsb)
    {
        reportDkjgZrrdhLsb.setCreateTime(DateUtils.getNowDate());
        return reportDkjgZrrdhLsbMapper.insertReportDkjgZrrdhLsb(reportDkjgZrrdhLsb);
    }

    /**
     * 修改贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     * 
     * @param reportDkjgZrrdhLsb 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     * @return 结果
     */
    @Override
    public int updateReportDkjgZrrdhLsb(ReportDkjgZrrdhLsb reportDkjgZrrdhLsb)
    {
        return reportDkjgZrrdhLsbMapper.updateReportDkjgZrrdhLsb(reportDkjgZrrdhLsb);
    }

    /**
     * 批量删除贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6
     * 
     * @param sjrqs 需要删除的贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6ID
     * @return 结果
     */
    @Override
    public int deleteReportDkjgZrrdhLsbByIds(String[] sjrqs)
    {
        return reportDkjgZrrdhLsbMapper.deleteReportDkjgZrrdhLsbByIds(sjrqs);
    }

    /**
     * 删除贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6信息
     * 
     * @param sjrq 贷款结构趋势-自然人单户或公类类单户4.3.1.1.1-5|6ID
     * @return 结果
     */
    @Override
    public int deleteReportDkjgZrrdhLsbById(String sjrq)
    {
        return reportDkjgZrrdhLsbMapper.deleteReportDkjgZrrdhLsbById(sjrq);
    }

    @Override
    public List<ReportDkjgZrrdhLsb> zrrdh(ReportDkjgZrrdhLsb reportDkjgZrrdhLsb, LoginUser userInfo) {
        List<ReportDkjgZrrdhLsb> doList = new ArrayList<ReportDkjgZrrdhLsb>();

        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportDkjgZrrdhLsb.getSjrq())) {
            if ("9999".equals(reportDkjgZrrdhLsb.getSjrq())) {
                reportDkjgZrrdhLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportDkjgZrrdhLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportDkjgZrrdhLsb.setSjrqs(sjrqs);
        doList = reportDkjgZrrdhLsbMapper.zrrdh(reportDkjgZrrdhLsb);
        return doList;
    }

    @Override
    public List<ReportDkjgZrrdhLsb> zrrdhhz(ReportDkjgZrrdhLsb reportDkjgZrrdhLsb, LoginUser userInfo) {
        List<ReportDkjgZrrdhLsb> doList = new ArrayList<ReportDkjgZrrdhLsb>();

        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportDkjgZrrdhLsb.getSjrq())) {
            if ("9999".equals(reportDkjgZrrdhLsb.getSjrq())) {
                reportDkjgZrrdhLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportDkjgZrrdhLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportDkjgZrrdhLsb.setSjrqs(sjrqs);
        doList = reportDkjgZrrdhLsbMapper.zrrdhhz(reportDkjgZrrdhLsb);

        return doList;
    }
}
